<%@ page import="java.sql.DriverManager"  %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Map" %>
<%@ page import="net.sf.jasperreports.engine.JREmptyDataSource" %>
<%@ page import="net.sf.jasperreports.engine.JRException" %>
<%@ page import="net.sf.jasperreports.engine.JasperCompileManager" %>
<%@ page import="net.sf.jasperreports.engine.JasperExportManager" %>
<%@ page import="net.sf.jasperreports.engine.JasperFillManager" %>
<%@ page import="net.sf.jasperreports.engine.JasperPrint" %>
<%@ page import="net.sf.jasperreports.engine.JasperReport" %>
<%@ page import="net.sf.jasperreports.view.JasperViewer" %>
<%@ page import="net.sf.jasperreports.engine.export.*" %>
<%@ page import="net.sf.jasperreports.j2ee.servlets.*" %>
<%@ page import="java.io.*" %>
<%@ page import="net.sf.jasperreports.engine.*" %>
<%@ page import="net.sf.jasperreports.engine.util.*" %>
<%@ page import="net.sf.jasperreports.engine.export.*" %>

<%
            String reportSource = application.getRealPath("report/templates/HelloReportWorld.jrxml");
            String reportDest = application.getRealPath("report/results/HelloReportWorld.html");

                       Map<String, Object> params = new HashMap<String, Object>();
            params.put("reportTitle", "Hello Report World");
            params.put("author", "Craig Conover");
            params.put("startDate", (new java.util.Date()).toString());
            params.put("parametro", new java.lang.Integer("4"));

            try {
                JasperReport jasperReport = JasperCompileManager.compileReport(reportSource);
                //JasperCompileManager.compileReportToFile(reportSource);
                // Make the driver class available.
                Class.forName("org.postgresql.Driver");

                // Create a connection to pass into the report.
                java.sql.Connection conn = DriverManager.getConnection(
                        "jdbc:postgresql://localhost:5432/srr", "postgres", "postgres");

                // Replace the empty JR datasource parameter with
                // the connection parameter named conn.
/*                String reportFileName = application.getRealPath("/report/templates/HelloReportWorld.jasper");
                File reportFile = new File(reportFileName);
                if (!reportFile.exists()) {
                throw new JRRuntimeException("File XXXXXXXXXXXXX The report design must be compiled first.");
                }
                Map parameters = new HashMap();
                parameters.put("ReportTitle", "Address Report");
                parameters.put("BaseDir", reportFile.getParentFile());
                 */
                JasperPrint jasperPrint =
                        JasperFillManager.fillReport(
                        jasperReport,
                        params,
                        conn);

                JasperViewer.viewReport(jasperPrint);

                JRHtmlExporter exporter = new JRHtmlExporter();


            } catch (JRException e) {
                e.printStackTrace();
            } // Exception handling for the Class.forName method.
            catch (ClassNotFoundException ex) {
                ex.printStackTrace();
            } // Exception handling for the DriverManager.getConnection method.
            catch (SQLException ex) {
                ex.printStackTrace();
            }

%>